let time = 0
let prevTime = 0
export default class Engine {
  private static instance: Engine;
  private started = false;
  private constructor() { }

  public static getInstance(): Engine {
    if (!Engine.instance) {
      Engine.instance = new Engine();
    }

    return Engine.instance;
  }

  start() {

    if (this.started) {
      return;
    }

    this.started = true;
    requestAnimationFrame((timestamp) => {
      // prevTime = Math.round(timestamp)
      prevTime = timestamp
      this.loop(timestamp)
    })
    console.log('engine started');
  }

  stop() {
    this.started = false;
    console.log('engine stopped');

  }

  loop = (timestamp: number) => {
    // timestamp = Math.round(timestamp)
    time += timestamp - prevTime
    prevTime = timestamp
    if (this.started) {
      this.logic();
      this.render()
      requestAnimationFrame(this.loop);
    }
  }
  logic() {
    // console.log('engine logic', time);
  }
  render() {
    // console.log('engine render', time);
  }
}